package by.demchenko.sample.webapp.page.home.panel;

import by.demchenko.sample.datamodel.Section;
import by.demchenko.sample.services.SectionService;
import by.demchenko.sample.webapp.page.home.BaseLayout;
import by.demchenko.sample.webapp.page.home.share.CourseDetailsPage;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.PackageResourceReference;

import javax.inject.Inject;

public class SectionPanel extends Panel {

    private Section section;

    public SectionPanel(String id, Section section) {
        super(id);
        this.section = section;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();

        //WebMarkupContainer liContainer = new WebMarkupContainer("wrapper-li");
        //add(liContainer);

        add(new Image("sectionImage", new PackageResourceReference(BaseLayout.class, "/share/images/" + section.getId() + ".png")));

        Link link = new Link<Void>("sectionLink") {
            @Override
            public void onClick() {
//                PageParameters pageParameters = new PageParameters();
//                pageParameters.add("page", "section");
                CourseDetailsPage sp = new CourseDetailsPage(section);
                setResponsePage(sp);
            }
        };
        add(link);
        Label lab = new Label("sectionName", new Model<String>(section.getName(getSession().getLocale())));
        link.add(lab);

    }
}
